<template>
	<view>
		<cu-custom bgColor="bg-blue">
			<block slot="content">个人中心</block>
		</cu-custom>
		<view class="top_box">

			<view class="mess_box" @tap="to_messagea()">
				<text class="iconfont icon-a-xiaoxi iconmess_text"></text>
				<text class="red_text" v-if="count>0">{{count}}</text>
			</view>


			<view class="one_box flex" @tap="to_companyEdit(company_id)">
				<view class="round_img">
					<block>
						<image :src="logo" class="image_school" mode="aspectFill" v-if="logo"></image>
						<view v-else class="company_nameBox">{{company_name[0]}}</view>
					</block>
				</view>
				<view class="flex" >
					<view class="shcool_box" >
						<view class="shcool_text">{{company_name}}</view>
						<view class="id_text">ID:{{company_id}}</view>
					</view>
					<view>
						<text class="cuIcon-right right_box"></text>
					</view>
				</view>
			</view>
		</view>

		<view class="icon_list">
			<view class="cu-bar tabbar" style="margin-bottom: 40rpx;">
				<view class="action" @tap="to_post()">
					<view class="iconfont icon-zhiwei-copy" style="font-size: 55rpx; margin-bottom: 30rpx;">
					</view>
					<text class="icon_textstyle">岗位管理</text>
				</view>
				<view class="action" @tap="to_cooperative(2)">
					<view class="iconfont icon-xuexiao " style="font-size: 55rpx; margin-bottom: 30rpx;"></view>
					<text class="icon_textstyle">学校管理</text>
				</view>
				<view class="action" @tap="to_studentmangement()">
					<view class="iconfont icon-shixi" style="font-size: 55rpx; margin-bottom: 30rpx;">
					</view>
					<text class="icon_textstyle">实训生管理</text>
				</view>
				<view class="action" @tap="to_training_circle()">
					<view class="iconfont icon-quanzi" style="font-size: 55rpx; margin-bottom: 30rpx;"></view>
					<text class="icon_textstyle">实训圈</text>
				</view>
			</view>
		</view>

		<view class="company_list">
			<view class="onebox_text">
				<text class="companyList_text">学校列表</text>
				<text class="view_more" @tap="to_cooperative(1)">查看更多</text>
			</view>

			<view class="box flex" v-for="(item,index) in list" :key='index'
				:style="index===list.length-1?'border-bottom-width: 0rpx;':''"
				@tap="to_cooperative_school(item.school_id)">
				<view class="headPortrait_box">
					<block>
						<image :src="item.logo"	class="company_iamge" v-if="item.logo!=''"></image>
						<view class="company_iamgeText" v-else>{{item.school_name[0]}}</view>
					</block>
				</view>
				<view class="companyListtext">
					<view class="companyName">
						<text>{{item.school_name}}</text>
					</view>
					<view class="companyType_box">
						<text>专科院校 | 1000-2000人</text>
					</view>
				</view>
				<view class="cuIcon-right right_click text-gray"></view>
			</view>
			<!-- <wzh-view v-for="(item,index) in list" :key='index' :image="item.logo" :toptext="item.school_name" :buttomtext="item.school_name" @tap="to_cooperative_school(item.school_id)"></wzh-view>
			 -->
		</view>
	</view>
</template>

<script>
	const {
		appLogin,
		httpGet,
		httpPost
	} = require("@/utils/common.js")
	let app = getApp();
	export default {
		data() {
			return {
				company_name:'',
				logo:'',
				company_id:0,
				page:'1',
				page_size:'10',
				list:[],
				count:0,
				timer:0,
			}
		},
		onLoad() {
			appLogin((user_info) => {
				console.log(user_info)
			})
		},
		onPageScroll(e){
			if(this.timer) return
			console.log(e)
			this.timer = 1;
			setTimeout(()=>{
				this.timer = 0;
			},200)
		},
		onShow() {
			this.page = 1;
			this.list = [];
			// 清空列表
			this.to_school()
			this.displayCompanyid()
			this.message()
			// 回到页面展示
		},
		onReachBottom() { // 页面滚动到底部
			this.page++
			this.to_school()
		},
		methods: {
			previewImage(logo){
				var arr = []
				arr.push(logo)
				uni.previewImage({
					current:0,
					urls: arr,
				})
			},
			// 如果有onWsMessage App页面就会触发该方法
			onWsMessage(data){
				console.log(data)
				if(data.action == 'new_notice'){
					// 获取当前消息数
					this.message();
				}
				// else if(data.action == "company_info"){
				// 	this.company_name = data.data.company_name
				// 	this.logo = data.data.logo
				// }
			},
			message(){
				httpGet({
					url:'/api/company/notice_all_count'
				}).then((res) => {
					console.log(res,)
					this.count = res.result.count
				})
			},
			displayCompanyid() {
				httpGet({
					url: '/api/company/my_staff',
				}).then(res => {
					console.log(res)
					this.company_id = res.result.company_id
					httpGet({
						url:'/api/company/info',
						data:{
							company_id:this.company_id
						}
					}).then((res) => {
						console.log(res)
						this.logo = res.result.logo
						this.company_name = res.result.company_name
						this.company_id = res.result.company_id
					})
				})
			},
			// 跳转岗位管理
			to_post() {
				uni.navigateTo({
					url: 'post_manage'
				});
			},
			// 跳转学生管理
			to_studentmangement() {
				uni.navigateTo({
					url: 'studentmanagement'
				});
			},
			// 跳转学校详情
			to_cooperative_school(school_id) {
				console.log(school_id)
				uni.navigateTo({
					url: 'cooperative_school?school_id=' + school_id
				})
			},
			// 获取学校列表接口信息
			to_school() {
				httpGet({
					url: '/api/school/list',
					data: {
						page: this.page,
						page_size: this.page_size
					}
				}).then(res => {
					console.log(res,)
					this.list = this.list.concat(res.result.list)
				})
			},
			// 跳转实训圈
			to_training_circle() {
				uni.navigateTo({
					url: 'training_circle'
				});
			},
			// 带type跳转学校管理
			to_cooperative(type) {
				uni.navigateTo({
					url: 'school_list?type=' + type
				});
			},
			// 跳转消息中心
			to_messagea() {
				uni.navigateTo({
					url: 'messagea'
				});
			},
			// 跳转企业编辑
			to_companyEdit(company_id) {
				// app.wsSend({action:'companyInfo'})
				console.log(this.company_id)
				uni.navigateTo({
					url: 'company_edit?company_id=' + company_id
				})
			}
		}
	}
</script>

<style>
	.mess_box {
		padding-top: 30rpx;
		position: absolute;
		right: 55rpx;
	}

	.red_text {
		min-width: 25rpx;
		height: 25rpx;
		border-radius: 180rpx;
		background-color: #ED1C24;
		color: #FFFFFF;
		position: absolute;
		line-height: 25rpx;
		top: 20rpx;
		left: 25rpx;
		text-align: center;
	}

	.iconmess_text {
		color: #FFFFFF;
		font-size: 44rpx;
	}

	.person_center {
		text-align: center;
		height: 105rpx;
		padding-top: 66rpx;
		font-size: 40rpx;
		color: #FFFFFF;
	}

	.top_box {
		background-color: #007AFF;
		height: 390rpx;
	}

	.one_box {
		width: 100%;
		height: 345rpx;
		padding-top: 95rpx;
	}

	.round_img {
		margin-left: 30rpx;
		border-radius: 180rpx;
		width: 123rpx;
		height: 123rpx;
		background-color: #FFFFFF;
		padding: 1rpx;
	}

	.shcool_box {
		margin-top: 15rpx;
		margin-left: 20rpx;
	}

	.shcool_text {
		color: #FFFFFF;
		font-size: 35rpx;
		margin-bottom: 26rpx;
	}

	.id_text {
		color: #d2dbfc;
		font-size: 24rpx;
	}

	.right_box {
		position: absolute;
		right: 25rpx;
		margin-top: 48rpx;
		color: #FFFFFF;
		font-size: 25rpx;
	}

	.icon_list {
		width: 720rpx;
		background-color: #FFFFFF;
		height: 215rpx;
		border-radius: 20rpx;
		margin: auto;
		margin-top: -120rpx;
		padding-top: 55rpx;
	}

	.icon_textstyle {
		font-size: 25rpx;
		color: #838383;
	}

	.round_style {
		border-radius: 180px;
		position: absolute;
		top: -5px;
		right: 23px;
		font-size: 10px;
		padding: 0px 5px;
		height: 14px;
		color: #ffffff;
		background-color: #ED1C24;
		height: 30rpx;
		width: 30rpx;
	}

	.company_list {
		width: 720rpx;
		border-radius: 20rpx;
		background-color: #FFFFFF;
		margin: auto;
		margin-top: 30rpx;
		padding-bottom: 15rpx;
	}

	.onebox_text {
		padding-top: 45rpx;
		margin-left: 35rpx;
		margin-bottom: 10rpx;
	}

	.companyList_text {
		font-size: 30rpx;
		color: #4d4d4d;
		font-weight: bold;
	}

	.view_more {
		position: absolute;
		right: 25rpx;
		color: #a3a3a3;
		font-size: 25rpx;
	}

	.imageRound_box {
		width: 105rpx;
		height: 105rpx;
		border-radius: 180rpx;
		margin-left: 40rpx;
		margin-top: 45rpx;
		background-color: #007AFF;
	}



	.headPortrait_box {
		width: 100rpx;
		height: 100rpx;
		border-radius: 180rpx;
		margin-top: 37rpx;
		background-color: #FFFFFF;
		margin-left: 20rpx;
	}

	.companyListtext {
		margin-top: 43rpx;
		margin-left: 20rpx;
	}

	.companyName {
		font-size: 30rpx;
		margin-bottom: 10rpx;
	}

	.companyType_box {
		font-size: 22rpx;
		color: #9d9d9d;
	}

	.company_num {
		font-size: 22rpx;
		color: #9d9d9d;
		margin-bottom: 30rpx;
	}

	.box {
		height: 175rpx;
		width: 670rpx;
		margin-left: 20rpx;
		border-bottom-width: 1rpx;
		border-bottom-style: solid;
		border-bottom-color: #e7e7e7;
	}

	.right_click {
		margin-top: 80rpx;
		position: absolute;
		right: 25rpx;
	}

	.image_school {
		width: 118rpx;
		height: 118rpx;
		border-radius: 180rpx;
	}

	.company_iamge {
		width: 100rpx;
		height: 100rpx;
		border-radius: 180rpx;
	}

	.company_iamgeText {
		width: 100rpx;
		height: 100rpx;
		border-radius: 180rpx;
		background-color: #FFFFFF;
		line-height: 100rpx;
		text-align: center;
		font-size: 30rpx;
		border-color: #c1c1c1;
		border-width: 1rpx;
		border-style: solid;
		color: #c1c1c1;
	}
	
	.company_nameBox{
		width: 118rpx;
		line-height: 118rpx;
		text-align: center;
		font-size: 35rpx;
	}
</style>
